package com.lsa.google.trials;

import junit.framework.TestCase;

public class SkippedProductCalculatorTest extends TestCase
{
    public void testVerify()
    {
        int[] array = new int[]{1,2,3,4,5};
        int[] result = SkippedProductCalculator.calculateForVerification(array);
        int[] controlResult = new int[]{2*3*4*5, 1*3*4*5, 1*2*4*5, 1*2*3*5, 1*2*3*4};
        
        assertTrue(compareArrays(result, controlResult));
    }
    
    public void testSmart()
    {
        int[] result = Task1SkippedMulCalc.calc(new int[]{1,2,3,4,5});
        int[] controlResult = new int[]{2*3*4*5, 1*3*4*5, 1*2*4*5, 1*2*3*5, 1*2*3*4};
        assertTrue(compareArrays(result, controlResult));
    }
    
    public void testStupids()
    {
        int[] array = new int[]{1,2,3,4,5};
        int[] result = SkippedProductCalculator.calculateOn2(array);
        int[] controlResult = new int[]{2*3*4*5, 1*3*4*5, 1*2*4*5, 1*2*3*5, 1*2*3*4};
        
        assertTrue(compareArrays(result, controlResult));
    }
    
    public static boolean compareArrays(int[] a1, int[] a2)
    {
        if (a1 == null || a2 == null)
        {
            return a1 == a2;
        }
        
        if (a1.length != a2.length)
        {
            return false;
        }
        
        for (int i = 0; i < a2.length; i++)
        {
            if (a1[i] != a2[i])
            {
                return false;
            }
        }
        
        return true;
    }
}
